import axios from "axios";
import { getAuthToken } from "@/router";

// 获取认证请求头
const getAuthHeader = () => ({
  headers: {
    Authorization: `${getAuthToken()}`,
  },
});

// 获取悬赏任务列表
export const getBountyList = (params = {}) => {
  return axios.get("/api/v1/bounty/list", {
    params,
    ...getAuthHeader(),
  });
};

// 获取悬赏任务详情
export const getBountyDetail = (id) => {
  return axios.get(`http://192.168.55.192:8080/api/bounty/detail/${id}`, getAuthHeader());
};

// 创建悬赏任务
export const createBounty = (data) => {
  return axios.post("/api/v1/bounty/create", data, getAuthHeader());
};

// 提交悬赏资源
export const submitBountyResource = (bountyId, data) => {
  return axios.post(`/api/v1/bounty/${bountyId}/submit`, data, getAuthHeader());
};

// 关闭悬赏任务
export const closeBounty = (bountyId) => {
  return axios.post(`/api/v1/bounty/${bountyId}/close`, {}, getAuthHeader());
};

// 采纳悬赏提交
export const acceptSubmission = (bountyId, submissionId) => {
  return axios.post(
    `/api/v1/bounty/${bountyId}/accept/${submissionId}`,
    {},
    getAuthHeader()
  );
};

// 驳回悬赏提交
export const rejectSubmission = (bountyId, submissionId) => {
  return axios.post(
    `/api/v1/bounty/${bountyId}/reject/${submissionId}`,
    {},
    getAuthHeader()
  );
};
